<%-- 
    Document   : ajaxAreas
    Created on : 01/06/2010, 21:24:12
    Author     : HP DV5
--%>
<%@page contentType="text/html" pageEncoding="windows-1252"%>
<%@page import="br.com.krossk.dao.AreaDAO" %>
<%@page import="br.com.krossk.model.Area" %>
<%@page import="java.util.ArrayList" %>
<%@page import="java.util.List" %>
<%
    //Retira o cache para o funcionamento do AJAX
    response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
    response.setHeader("Pragma","no-cache"); //HTTP 1.0

%>

<%
response.setCharacterEncoding("windows-1252");
 String q =request.getParameter("q");
 String action =request.getParameter("action");
 List<Area> areas = new ArrayList<Area>();

 if(action.equals("incluir")){
     Area aNew = new Area();
     aNew.setNomeArea(q);
     AreaDAO.getInstance().save(aNew);
 }

 if(action.equals("alterar")){
    Area aAlt = AreaDAO.getInstance().getById(Integer.parseInt(request.getParameter("aux")));
    if(aAlt != null){
        aAlt.setNomeArea(q);
        AreaDAO.getInstance().update(aAlt);
    }
    
 }
 

 areas = AreaDAO.getInstance().getAll();
 int i = 2;
 String classe;

 
%>
 <table class="tabDados" border="1px" width="500px"><tr class="tit"><td colspan="2" align="center">Areas</td></tr>
 <%for(Area a: areas){

     if(i%2==0){
        classe = "item";
     }else{
        classe = "altItem";
     }
    %><tr class="<%=classe%>"><td align="center" id="td<%=a.getIdArea()%>"><%=a.getNomeArea()%></td><td align="center"><label id="lbl<%=a.getIdArea()%>" class="lblAlterar" onclick="alterarArea(<%=a.getIdArea()%>,this);"><img src="../../img/GerenciamentoEntidades/alterar.png"></label></td></tr>
    <% i +=1;}%></table>


